/**
 * 面板
 * @author wonderful wuketidai@foxmail.com
 * @create 20150626
 */
(function(){
/*	var opt={
			isDrag:true,//如果为true就可拖拽
			width:400,//高
 			haveUpload:true,//是否有上传文件功能
			uploadParam:{	//上传模块参数，若haveUpload为true必传
			uploadUrl:""	//上传文件URL
			},
			height:500,//宽
			valForm:{
				valParam:[//验证参数
                 {
	              inputname:"loginName",
	              isnull:true,
	              isnullmsg:"登录名不能为空！",
	              exists:true,
	          	  existsmsg:"用户名已被使用！",
	          	  postdata:function(){
	          		return "loginName="+$("#loginName").val();
	          	  },
	          	  url:basePath+"gzmli/system/isLoginNameExists.wdf",
	          	  istrue:1,
	          	  successfulMsg:"用户名输入正确",
	          	  showMsg:"",
	          	  event:"blur"
                  },
			       {
			    	inputname:"userName",
			    	isnull:true,
			    	isnullmsg:"用户姓名不能为空",
			    	event:"blur"
			       }
			       ]
			},//验证
			action:"",//表单提交地址
			gridOption : tunnelGridOpt,//wdfGrid参数对象
			treeOption:treeOption,//zTree参数
			treeDataRoot:"",//zTree数据的根属性
			isShowSearchBar:false,//控制是否显示搜索表单
			event:{
			ztreeDataFilter:function(zTreeObj,nodes){//zTree非异步下的数据过滤事件
				
			},
			okBtnClick:function(eventObj,panel,{//该参数为表单模式下启用，通过在函数里设success的值来控制表单提交
			                                    //0不提交，继续等待 1提交 2 退出
	    					success:null,
	    					msg:"",
	    			}){
				
			},
			resetBtnClick:function(eventObj,panel){
				
			},onClosed:function(obj){
			
			},
			submitSuccessed:function(data,panelObj){//提交成功后执行data提交后服务端返回的数据，必须包含执行状态state(0/1),panelObj当前面板对象
			
			},onShowed:function(panelObj){//面板显示的时候触发
			
			}
		    },
		    extendsBtn:[//扩展按钮,GridPanel模式下有效
		 		   {
		 			label:"",//按钮名称
		 			id:"userTunnelBind",//按钮id
		 			className:"filterBtn",//按钮样式名
		 			clickEvent:function(eventObj,panel,grid){
		 			
		 			}
			       }]
			};
	
	function showMsg(msg){
		var msgBar=$("<div class='msgBar'>"+msg+"</div>");
		$("#addUserPanel").append(msgBar);
		msgBar.animate({"opacity":1},500);
	};*/
	
	
	$.fn.extend({"wdfPanel":function(type,opt){

		var obj=this;
		var titleBar=this.find(".titleBar");
		var splitBar=this.find(".split");
		var closeBtn=this.find(".closeBtn");
		var content=this.find(".content");
		var btnBar=this.find(".btnBar");
		var okBtn=btnBar.find(".okBtn");
		var resetBtn=btnBar.find(".resetBtn");
		var quxiao_btn = obj.find(".quxiao_btn");
		var searchBar;
		var wdfGrid;
		var actionBar;
		var isTriggerCloseEvent=true;
        //面板关闭方法
		this.close=function(isTriggerEvent){
			if(!isTriggerEvent&&isTriggerEvent==false)
                isTriggerCloseEvent=false;
			if(closeBtn.length>0){
                closeBtn.click();
			}else{
                quxiao_btn.click();
			}
		}

		//content.html("");
		var pannel_bg = this.parent(".pannel_bg");
        pannel_bg.css("height","100%");

		function showMsg(msg){
			var msgBar=$("<div  class='msgBar'>"+msg+"</div>");
	    	$(".msgBar").remove();
	    	obj.append(msgBar);
	    	msgBar.animate({"opacity":1},500);
		}
		function showBg(content){
			var bg=$("<div class='bg'></div>").appendTo(content);
			var bg_LoadProgress=$("<div class='bg_LoadProgress'></div>").appendTo(content);
		}
		function removeBg(content){
			content.find(".bg").remove();
			content.find(".bg_LoadProgress").remove();
		};

		var btnBarHeight=obj.find(".btnBar").height();
		if(opt.isDrag){//可拖拽
            obj.find(".titleBar").css("cursor","move");
            if(type=="GridPanel"){
                obj.find(".titleBar").dragDiv(".gridPanel");
            }else{
                obj.find(".titleBar").dragDiv(".panel");
            }

		}
		if(type=="GridPanel"){

		}else if(type=="TreePanel"){

            content.height(opt.height-166);
		}else{
		//	content.height(opt.height-btnBarHeight);
		}


		if(opt.bombType == 1){
            closeBtn.hide();
            titleBar.addClass("bombType1_title");
            content.addClass("bombType1_content");
		}else if(opt.bombType == 2){
            titleBar.addClass("bombType2_title");
            content.addClass("bombType2_content");
            content.css("maxHeight",(opt.height-170)+'px');
		}else if(opt.bombType == 3){
            titleBar.addClass("bombType3_title");
            content.addClass("bombType3_content");
		}else if(opt.bombType == 4){
			titleBar.addClass("bombType3_title");
			content.addClass("bombType2_content");
		}

        quxiao_btn.bind("click",function () {
            if(isTriggerCloseEvent){
        	if(opt.event&&opt.event.onClosed)
            {
                isTriggerCloseEvent=true;
                opt.event.onClosed(obj);
            }
            }
            var resetBtn=obj.find(".resetBtn");
            if(resetBtn.length>0){
                resetBtn.data("isClose",true);
                resetBtn.click();
            }
            if(obj.find('#uploadfile').size()>0){

            }
            obj.css("display","none");
            obj.parent(".pannel_bg").hide();
            $(".tempFileList").remove();
        })
	    closeBtn.bind("click",function(){

	    	if(opt.event&&opt.event.onClosed)
			{
				if(isTriggerCloseEvent){
                    isTriggerCloseEvent=true;
	    		if(opt.event.onClosed(obj)==false)
	    			return;
                }
			}
	    	var resetBtn=obj.find(".resetBtn");
    		if(resetBtn.length>0){
    			resetBtn.data("isClose",true);
    			resetBtn.click();
    		}
    		if(obj.find('#uploadfile').size()>0){
            }
	    	obj.css("display","none");
            obj.parent(".pannel_bg").hide();
            $(".tempFileList").remove();
            $("div[id*=_wdfGridEditRowSel_]").remove();
	    });

	   //如果是表单面板
	   if(type=="FormPanel"){

	    if(opt.valForm&&opt.valForm.valParam){
	    	createValidateEvent(function(){
	    		return opt.valForm.valParam;
	    	});
	    }
	    if(opt.action||opt.action==""){
	    	okBtn.bind("click",function(){
	    		if(opt.event["okBtnClick"]){
	    			//标识，okBtnClick后判断表单是否提交
	    			var identifying={
	    					success:null,
	    					msg:"",
	    			}
	    			opt.event["okBtnClick"]($(this),obj,identifying);
	    			setTimeout(intervalRef,100);
	    			//间隔判断标识状态
	    			function intervalRef(){
	    				if(identifying.success==0){
	    					setTimeout(intervalRef,100);
	    				}else if(identifying.success==1){
	    					submitForm();
	    				}else if(identifying.success==null){
	    					submitForm();
	    				}else{
	    					return;
	    				}
	    			}
	    			return;
	    		}
	    		//直接提交
	    		submitForm();
	    		//表单提交
	    		function submitForm(){
	    		if(opt.valForm&&opt.valForm.valParam&&!executeVal(opt.valForm.valParam)){
	    			return;
	    		}
	    		$.wdfProgress.progress("请稍等...",obj,"center");
	    		setTimeout(function(){
	    		var param=obj.find("form").serialize();
	    		// param=encodeURI(param);
	    		//alert(param);
	    		$.ajax({
		    		   url:opt.action,
		    		   //processData: false,
		    		   //data: xmlDocument,
		    		   data:param,
		    		   dataType:"json",
		    		   type: "post",
		    		   contentType:"application/x-www-form-urlencoded;",
		    		   beforeSend:null,
		    		   success:function(data){
		    			   if(data&&(data.status==1 || data.state==1)){
		    				   if(data&&data.msg)
				    			   $.wdfProgress.showMsg(data.msg,obj,false);
		    			   }else{
		    				 $.wdfProgress.showMsg(data.msg ,obj,false);
		    				 return;
		    			   }
		    			   //提交成功后执行
		    			   if(opt.event.submitSuccessed){
		    				  opt.event.submitSuccessed(data,obj);
		    			   }
		    		    },
		    		   error:function (XMLHttpRequest, textStatus, errorThrown) {
		    			   $.wdfProgress.showMsg("网络延迟或系统异常！",obj,false);
		    		    }});

	    	},300);
	     }
	    });}
	    	obj.css("display","none");
           obj.parent(".pannel_bg").hide();
	    	/*obj.find("div:.content").bind("click",function(e){
				stopBubble(e);
			});
	    	obj.find("div:.content").bind("mousedown",function(e){
				stopBubble(e);
			});*/

	    }//表单面板end

	   else if(type=="GridPanel"){
		    searchBar=createSearchBar(content,opt);
		    wdfGrid=createWdfGrid(content,opt);
		    actionBar=createActionBar(content,opt,wdfGrid,searchBar,obj);
            formBar = createFormBar(content,opt);
            obj.parent(".pannel_bg").hide();
            obj.css("display","none");

	   }
	   else if(type=="TreePanel"){
		   var treeObj=$("<ul id='"+opt.id+"_ZTree' class='ztree'></ul>").appendTo(content);
		   $.wdfProgress.progress("请稍等...",obj);
		   $.ajax({
				   url:opt.action,
				   dataType:"json",
				   type: "post",
				   contentType:"application/x-www-form-urlencoded",
				   beforeSend:null,
			       data:opt.param,
				   success:function(data){
					    if(opt.event&&opt.event.ztreeDataFilter){
					    	if(data.nodes){
					    		opt.event.ztreeDataFilter(data.nodes);
					    		 $.fn.zTree.init(treeObj,opt.ztreeOption,data.nodes)
					    	}else if(opt.treeDataRoot){
					    		opt.event.ztreeDataFilter(data[opt.treeDataRoot]);
					    		$.fn.zTree.init(treeObj,opt.ztreeOption,data[opt.treeDataRoot]);
					    	}

					    }
					    else{
					    	if(data.nodes){
					    		 $.fn.zTree.init(treeObj,opt.ztreeOption,data.nodes);
					    	}else if(opt.treeDataRoot){
					    		$.fn.zTree.init(treeObj,opt.ztreeOption,data[opt.treeDataRoot]);
					    	}
					    }

				    	$.wdfProgress.showMsg("数据加载完成！",obj);
				    	$.wdfProgress.progRemove(obj);
				    },
				    error:function (XMLHttpRequest,textStatus,errorThrown) {
				    	$.wdfProgress.showMsg("系统错误或网络延迟！",$("body"),false);
				    }});

		   if(opt.event&&opt.event.okBtnClick&&okBtn.length>0){
			   okBtn.bind("click",function(){
				   opt.event.okBtnClick($(this),obj);
			   });
		   }

		   if(opt.event&&opt.event.onReset&&resetBtn.length>0){
			   resetBtn.bind("click",function(){
				   opt.event.onReset($(this),obj);
			   });
		   }

		   obj.css("display","none");
           obj.parent(".pannel_bg").hide();
	   }else if(type=="Custom"){
			obj.find(".content").css("height","80%");
	   }
	   obj.show=function(title,gridInit){

	    	obj.css("display","block");
	    	pannel_bg.css("height","100%");
	    	pannel_bg.show();

		   var btnBar;
		   var titleBar=obj.find(".titleBar");
		   var searchBar=obj.find(".searchBar");
		   if( obj.find(".btnBar").size()>0){
			   btnBar=obj.find(".btnBar");
		   }else if(obj.find(".btnContent").size()>0){
			   btnBar=obj.find(".btnContent");
		   }
		   titleBar.find(".title").text(title);

           var uploader;
           if(opt.haveUpload){

               obj.find("#"+obj.attr("id")+"uploader").remove();

               var uploadfile = $('<div id="'+obj.attr("id")+'uploader" class="uploader_box"></div>').appendTo(content);

               var form_group = $('<div class="form-group form-inline"></div>').appendTo(uploadfile);
               var picker = $('<div id="'+obj.attr("id")+'picker">选择文件</div>').appendTo(form_group);
               var $thelist = $('<div id="'+obj.attr("id")+'thelist" class="uploader-list"></div>').appendTo(uploadfile);

			   var btnBar = $('<div class="btnBar"></div>');
               btnBar.appendTo(uploadfile);

               var ctlBtn = $('<input type="button" value="开始上传" id="'+obj.attr("id")+'ctlBtn" class="okBtn zhuanjiao_btn"/>').appendTo(btnBar);
				var uploadCloseBtn = $('<input value="取消" class="quxiao_btn" type="button">').appendTo(btnBar);
               var $upbtn = obj.find('#'+obj.attr("id")+'ctlBtn');
               uploadCloseBtn.bind("click",function () {
				  obj.find(".closeBtn").click();
               });
			   uploader = WebUploader.create({
			   	   //auto:true,
                   resize: false, // 不压缩image
                   swf: basePath+'resource/plugins/webuploader/js/uploader.swf', // swf文件路径
                  // server: basePath+'file/wdfUpload.wdf?statusName=111&projectDocType=1', // 文件接收服务端。
				   server:opt.uploadParam.uploadUrl,
                   pick: {id:'#'+obj.attr("id")+'picker',
				   		style:{
                   			color:'#000'
						}
				   }, // 选择文件的按钮。可选
                   chunked: false, //是否要分片处理大文件上传
                 //  chunkSize:2*1024*1024 //分片上传，每片2M，默认是5M
                   //auto: false //选择文件后是否自动上传
                   // chunkRetry : 2, //如果某个分片由于网络问题出错，允许自动重传次数
                   //runtimeOrder: 'html5,flash',
                   // accept: {
                   //   title: 'Images',
                   //   extensions: 'gif,jpg,jpeg,bmp,png',
                   //   mimeTypes: 'image/*'
                   // }
               });
               uploader.on( 'fileQueued', function( file ) {
               	var size = file.size;
               	if(size>1024){
                    size = (size/1024) .toFixed(2)+"kb";
				}else if(size>1024*1024){
                    size = (size/(1024*1024)) .toFixed(2)+"mb";
				}else{
                    size = size + "b";
				}
				var file_ext = file.ext;
				var file_type_class = '';
				if(file_ext == "jpg" || file_ext =="JPG"){
                    file_type_class = "jpg";
				}else if(file_ext == "png" || file_ext =="PNG"){
                    file_type_class = "png";
				}else if(file_ext == "docx" || file_ext =="doc"){
                    file_type_class = "doc";
				}else if(file_ext == "xls" || file_ext =="xlsx"){
                    file_type_class = "xlsx";
				}else if(file_ext == "ppt" || file_ext =="pptx"){
                    file_type_class = "ppt";
				}else if(file_ext == "txt" || file_ext =="TXT"){
                    file_type_class = "txt";
                }
                   $thelist.append( '<div id="' + file.id + '" class="file_item '+file_type_class+'">' +
                       '<div class="upload_list_left"><p class="info">' + file.name + '</p>' +
						//2019-11-11 yuanp 给删除按钮添加一个自定义属性，方便前端做图片上传限制的处理;具体见：养护计划IMPan.js中onUploadFileQueued属性的写法；
                       '<p class="state" imgSize="'+size+'">文件大小：'+size+'</p></div>' +'<span class="ion-close-round">删除</span>'+ '</div>' );
					obj.find(".webuploader-pick").css("height","48px");
                   opt.event.onUploadFileQueued(file);
               });
               uploader.on( 'uploadProgress', function( file, percentage ) {
                   var $li = $( '#'+file.id ).find(".upload_list_left");
                       var $percent = $li.find('.progress-bar');

                   $li.find(".progress").remove();
                   // 避免重复创建
                 //  $li.find('.progress-bar').html("");
                       $percent = $('<div class="progress progress-striped active">' +
                           '<div class="progress-bar" role="progressbar" style="width:0%">' +
                           '</div>' +
                           '</div>').appendTo( $li );
                   $percent.find(".progress-bar").css( 'width', percentage * 100 + '%' );
                   $( '#'+file.id ).find('.state').hide();
               });
               uploader.on('beforeFileQueued',function (file) {

               });
               // 文件上传成功
               uploader.on( 'uploadSuccess', function( file ,data) {
               	delete data._raw;
                   file.type=file.ext;
                   $( '#'+file.id ).find('.state').text('已上传');
                   opt.event.onUploadSuccessed(file,data);
               });

               // 文件上传失败，显示上传出错
               uploader.on( 'uploadError', function( file ) {
                   $( '#'+file.id ).find('p.state').text('上传出错');
               });
               // 完成上传完
               uploader.on( 'uploadComplete', function( file ) {

               });
				uploader.on('uploadFinished',function () {//上传结束
                    opt.event.uploadComplete();
                });
               $upbtn.on('click', function () {
               	if(uploadfile.find(".file_item").size()>10){
                    $.wdfProgress.progress("文件数量不能大于10！", $("body"),true,false);
                    $.wdfProgress.progRemove($("body"),false,1000);
                    return false;
				}

                   if ($(this).hasClass('disabled')) {
                       return false;
                   }

                   uploader.upload();

               });
               $thelist.on("click", ".ion-close-round", function () {
                   var fileItem = $(this).parent();
                   var id = $(fileItem).attr("id");
                   uploader.removeFile(id, true);
                   $(fileItem).fadeOut(function () {
                       $(fileItem).remove();
                   });

               });
               obj.find('.webuploader-pick').next("div").css("width","100%");
               obj.find('.webuploader-pick').next("div").css("height","100%");
           }

			//content.height(opt.height-splitBar[0].offsetHeight*2-titleBar[0].offsetHeight-btnBarHeight-10);

			if(!gridInit){
			//	content.height(opt.height-btnBarHeight-titleBarHeight-30);
			}

           obj.css({"margin-top":opt.height/2*-1,"margin-left":obj.width()/2*-1});
           obj.css({"left":"50%","top":"50%"});

	    	if(gridInit){
				var gridContent=obj.find(".gridContent");
				//延迟加载，以便获取到准确的相关元素尺寸。
				setTimeout(function(){
					gridContent.height(opt.height-titleBar.height()-searchBar.height()-10);
					if(searchBar){
						opt.gridOption.param = searchBar.find("form").serialize();
					}
					if(wdfGrid){
						wdfGrid.wdfGrid("init",opt.gridOption);
					}
					if(opt.event&&opt.event["onShowed"]){
						opt.event.onShowed(obj);
					}
					if(opt.formOption){

					}
				},10);
	    	}

		if(opt.bombType == 2){
            var width = $(window).width();
            obj.css({"width":width+"px","margin-left":width/2*-1});
            var height = $(window).height();
            obj.css({"height":height+"px","margin-top":height/2*-1});

            //判断是否缓存面板尺寸监听函数,避免重复绑定造成不必要的浏览器负担。
            if(obj.data("resizePanelFun")){
				obj.data("resizePanelFun")();
			}else{
				obj.data("resizePanelFun", function () {
						var width = $(window).width();
						var height = $(window).height();
						// obj.css({"width":width+"px","margin-left":width/2*-1});
						obj.css({"width":width,"height":height,"left":0,"top":0,"margin-left":0,"margin-top":0});
						// obj.css({"height":height+"px","margin-top":height/2*-1});
						content.css("maxHeight",(height-titleBar.height()-btnBar.height()-25));
				});
				$(window).bind('resize',obj.data("resizePanelFun")).resize();
			}

		}else{
	    	if(opt.width && opt.height){
                obj.css({"width":opt.width+"px","margin-left":opt.width/2*-1});
                obj.css({"height":opt.height+"px","margin-top":opt.height/2*-1});
			}else{
                var width = $(window).width()-300;
                var height = $(window).height()-186;
                obj.css({"width":width+"px","margin-left":width/2*-1});
                obj.css({"height":height+"px","margin-top":height/2*-1});
                $(window).on('resize', function () {
                     width = $(window).width()-300;
                     height = $(window).height()-186;
                    obj.css({"width":width+"px","margin-left":width/2*-1});
                    obj.css({"height":height+"px","margin-top":height/2*-1});
                    if(content.find(".btnBar").size()>0){
                        content.css("maxHeight",(obj.height()-obj.find(".titleBar").height())+'px');
                    }else{

                        content.css("maxHeight",(obj.height()-obj.find(".titleBar").height()-obj.find(".btnContent").height())-10+'px');
                    }

                }).resize();
			}
		}
		   // obj.show();
           obj.css("display","block");
	    };
            obj.find(".formContent").find(".verificationInput").show();

	    return obj;

	}});


function createWdfGrid(contentObj,opt){

		var wdfGrid=$("<div id='"+opt.id+"_WdfGrid' style='background-color:white'></div>");
		var gridContent=$("<div class='gridContent'></div>");
		contentObj.append(gridContent);
		gridContent.append(wdfGrid);
    	gridContent.next(".btnsBar").appendTo(gridContent);
		return wdfGrid;

	}

function createSearchBar(contentObj,opt){

	var searchBar=$("<div class='searchBar'></div>");

	var form=$("<form id='"+opt.id+"_sonPage_searchForm'></form>");
	contentObj.append(form);
	form.append(searchBar);
	if(opt.searchInput)
		{
		$(opt.searchInput).each(function(index){
			var input;
			if(this.type=="hidden")
				{
				var input=$("<input/>");
				input.attr("id",this.id);
				input.attr("type",this.type);
				input.attr("name",this.name);
				if(this.val)
					input.val(this.val);
				if(this.isConst)
					input.attr("isConst",'true');
				form.append(input);
				return;
				}
			var searchBar_Block= $("<div class='block' ></div>");
			var searchInputLabel = $("<div class='label'>"+this.label+"：</div>");
			var searchInput = $("<div class='input'></div>");


			searchBar_Block.append(searchInputLabel);
			searchBar_Block.append(searchInput);
			if(this.type=="select"){
			   input=$("<select></select>");
			   input.attr("id",this.id);
			   input.attr("name",this.name);
			   var option = "";
			   if(this.data){
                   for(var i=0;i<this.data.length;i++){
                       option += '<option value="'+this.data[i].value+'">'+this.data[i].text+'</option>'
                   }
                   input.append(option);
			   }

			}else{
			   input=$("<input/>");
			   input.attr("id",this.id);
			   input.attr("type",this.type);
			   input.attr("name",this.name);
			};
			if(this.val)
				input.val(this.val);
			if(this.isConst)
				input.attr("isConst",'true');

            searchInput.append(input);
            searchBar.append(searchBar_Block);

		});
       //     searchBar_Blue.find(".tosearch_panel").remove();

		//重置按钮
		var hasInputText = 0;

		$(opt.searchInput).each(function(index){
			if(this.type=="text"||this.type=="select"){
				hasInputText = 1;
			}
		})
		if(hasInputText == 1)
		{
		var resetBtn=$("<div class='optContent'><input type=\"button\" id='"+opt.id+"_sonPage_searchBtn' class=\"searchBtn\"  value=\"查询\"><input type='button' class='restBtn' id='"+opt.id+"_sonPage_resetBtn'  value='重置' /></div><div class='split'></div>");
            searchBar.append(resetBtn);
		}
		}

	//回车绑定事件
    $("input[type=text]").keyup(function(e){
        var theEvent = window.event || e;
        if(theEvent.keyCode ==13){
        	//alert("test");
        	$("#"+opt.id+"_sonPage_btn").click();

        }
    });
    $("select").change(function () {
		$("#"+opt.id+"_sonPage_btn").click();
    })

	return searchBar;
}


function createActionBar(contentObj,opt,wdfGrid,searchBar,obj){
	var actionBar= "";
	if(opt.hasOwnProperty("extendsBtn")){   //添加是否有拓展按钮判断，yuanp 2019-11-04，没有拓展按钮让其为空，不影响格式化面板的样式
		actionBar = $("<div class='actionBar'></div>");
	}
	if(opt.searchInput&&opt.searchInput.length>0)
	{

	 	//重置按钮点击事件
	 	$("#"+opt.id+"_sonPage_resetBtn").bind("click",function(){
	 		//由于sel<Z-tree>下拉选不能使用form表单重置，需手动找到对应的下拉选，重置值为空 yuanp
			var selInputs = $('#'+opt.id+'_sonPage_searchForm').find(".selInput");
			if(selInputs.length != 0){
				for (var i =0 ;i<selInputs.length;i++){
					$(selInputs[i]).wdfSel("setVal","");
				}
			}

	 		$('#'+opt.id+'_sonPage_searchForm')[0].reset();
            if(opt.event&&opt.event.onReset){
                    opt.event.onReset($(this),obj);
            }
	 		opt.gridOption.param = $("#"+opt.id+"_sonPage_searchForm").serialize();
	 		wdfGrid.wdfGrid("reload",opt.gridOption);
	 	});
        $('#'+opt.id+'_sonPage_searchBtn').bind("click",function () {
            opt.gridOption.param = $("#"+opt.id+"_sonPage_searchForm").serialize();
            wdfGrid.wdfGrid("reload",opt.gridOption);
        });
        if(opt.searchInput&&opt.searchInput.length>0){
        	var onHaveHidden = true;
        	for (var i=0;i<opt.searchInput.length;i++){
				if(opt.searchInput[i].type != "hidden"){
                    onHaveHidden = false;
				}
			}

        }

	}

    if(opt.inputBtn){

			$(opt.inputBtn).each(function(i,inputBtn){
				//通过自定义按钮类型添加不同的样式
				var customerBtn;
				if(inputBtn.btnType == "add"){
					customerBtn=$('<input type="button" class="input_button myAddBtn" id="'+inputBtn.id+'" value="'+inputBtn.title+'"/>');
				}else if(inputBtn.btnType == "upload"){
					customerBtn=$('<input type="button" class="input_button myUploadBtn" id="'+inputBtn.id+'" value="'+inputBtn.title+'"/>');
				}else{
					customerBtn=$('<input type="button" class="input_button" id="'+inputBtn.id+'" value="'+inputBtn.title+'"/>');
				}
					
                if(inputBtn.onClick){
                	customerBtn.bind("click",function(e){
                        stopPropagation(e);
                		inputBtn.onClick($(this),contentObj,wdfGrid);
                	});
                }
                
                actionBar.append(customerBtn);
			});
            
		}

	
	if(opt.extendsBtn)
		{
		$(opt.extendsBtn).each(function(i,btnParam){
			var btn=$("<a></a>");
			btn.attr("id",btnParam.id);
			btn.attr("class",btnParam.className);
			btn.text(btnParam.label);	
			actionBar.append(btn);
			if(btnParam.clickEvent){
				btn.bind("click",function(){
					btnParam.clickEvent($(this),contentObj,wdfGrid);
				});
			}
		});
		}
	wdfGrid.parent().before(actionBar);
	contentObj.css("display","block");
	//动态计算表格控件高度
	// opt.gridOption.height=opt.height-98;
	// wdfGrid.wdfGrid("init",opt.gridOption);
	// contentObj.css("display","none");
	if(searchBar.find("input[type=text]").length<1){
		actionBar.find(".searchBtn").hide();
		actionBar.find(".resetBtn").hide();
	}
	return actionBar;
}

function createFormBar(contentObj,opt) {
	var obj = contentObj.parent();
	if(opt.formOption){
        var formBar=$("<div class='wdfformBar'></div>");
        contentObj.append(formBar);
        var form=$("<form></form>");
        formBar.append(form);
        $(opt.formOption.formInput).each(function(index){
            var input;
            if(this.type=="hidden")
            {
                var input=$("<input/>");
                input.attr("id",this.id);
                input.attr("type",this.type);
                input.attr("name",this.name);
                if(this.val)
                    input.val(this.val);
                if(this.isConst)
                    input.attr("isConst",'true');
                form.append(input);
                return;
            }
            var col=$("<div class='col'></div>");
            if(this.type == "checkbox"||this.type == "radio"){
                var title=$("<div class='title'>"+this.title+"</div>");
			}else{
                var title=$("<div class='title'>"+this.title+"："+"</div>");
			}

            if(this.type !="checkbox" && this.type !="radio"){
                col.append(title);
			}

            if(this.type=="select"){
                input=$("<select></select>");
                input.attr("id",this.id);
                input.attr("name",this.name);
            }else if(this.type=="textarea"){
            	input=$("<textarea></textarea>");
            	input.attr("id",this.id);
                input.attr("name",this.name);
            }
            else{
                input=$("<input/>");
                input.attr("id",this.id);
                input.attr("type",this.type);
                input.attr("name",this.name);
            }
            if(this.val)
                input.val(this.val);
            if(this.isConst)
                input.attr("isConst",'true');
            if(this.isClear){
                col.css("clear","both")
			}

            col.append(input);
            if(this.type =="checkbox" || this.type =="radio"){
                title.css("paddingLeft",0);
                title.css("text-align","left");
                col.append(title);
            }
            form.append(col);
            form.attr("action",opt.formOption.action);
        });
        contentObj.parent().find("#doSubmit").click(function () {
			if(opt.formOption.beforeSubmit(this)){
				var canSub = true;
                $(opt.formOption.formInput).each(function(index){
                	if(this.isnull == true && contentObj.find("#"+this.id).val()==""){
                        contentObj.find("#"+this.id).css("borderColor","#ff0000");
                        contentObj.find("#"+this.id).css("backgroundColor","#f5a5a5");
                        canSub = false;
					}else{
                        contentObj.find("#"+this.id).css("borderColor","#dadada");
                        contentObj.find("#"+this.id).css("backgroundColor","none");
					}
				});
                if(canSub){
                    $.wdfProgress.progress("请稍等...",contentObj.parent(),"center");
                    var param=form.serialize();
                    $.ajax({
                        url:basePath+"gzmli/project/listUserRoles",
                        //processData: false,
                        //data: xmlDocument,
                        data:param,
                        dataType:"json",
                        type: "post",
                        contentType:"application/x-www-form-urlencoded",
                        beforeSend:null,
                        success:function(data){
                            if(data&&(data.status==1 || data.state==1)){
                                if(data&&data.msg)
                                    $.wdfProgress.showMsg(data.msg,obj,false);
                            }else{
                                $.wdfProgress.showMsg("操作失败！",obj,false);
                                return;
                            }
                            //提交成功后执行
                            if(opt.event.submitSuccessed){
                                opt.event.submitSuccessed(data,obj);
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown) {
                            $.wdfProgress.showMsg("网络延迟或系统异常！",obj,false);
                        }});
				}


			}
        })
	}



    return formBar;
    
}

})();
(function($) {
    $.fn.dragDiv = function(divWrap) {
        return this.each(function() {
            var $divMove = $(this);//鼠标可拖拽区域
            var $divWrap = divWrap ? $divMove.parents(divWrap) : $divMove;//整个移动区域
            var mX = 0, mY = 0;//定义鼠标X轴Y轴
            var dX = 0, dY = 0;//定义div左、上位置
            var isDown = false;//mousedown标记

            var $removeDiv = $divMove.find(".remove_btn");

            if(document.attachEvent) {//ie的事件监听，拖拽div时禁止选中内容，firefox与chrome已在css中设置过-moz-user-select: none; -webkit-user-select: none;
                $divMove[0].attachEvent('onselectstart', function() {
                    return false;
                });
            }
            $divMove.mousedown(function(event) {
                var event = event || window.event;

                mX = event.clientX;
                mY = event.clientY;
                dX = $divWrap.offset().left;
                dY = $divWrap.offset().top;
                var x = event.clientX;//鼠标滑动时的X轴
                var y = event.clientY;//鼠标滑动时的Y轴
                $divWrap.css({"left": x - mX + dX, "top": y - mY + dY});//div动态位置赋值
                $divWrap.css("marginLeft","0");
                $divWrap.css("marginTop","0");
                isDown = true;//鼠标拖拽启动
            });
            $(document).mousemove(function(event) {
                var event = event || window.event;
                var x = event.clientX;//鼠标滑动时的X轴
                var y = event.clientY;//鼠标滑动时的Y轴
                if(isDown) {
                    $divWrap.css({"left": x - mX + dX, "top": y - mY + dY});//div动态位置赋值
                }
            });
            $divMove.mouseup(function() {
                isDown = false;//鼠标拖拽结束
            });
            $removeDiv.click(function () {
                $divWrap.hide(300);
            });
        });
    };
})(jQuery);


function slideDownInput(e) {
    $(e).hide();
    $(e).parent(".slideInput_box").find(".slideUpBtn").show();
	$(e).parents(".formContent").find(".block").show();
}

function slideUpInput(e) {

	$(e).hide();
	$(e).parent(".slideInput_box").find(".slideDownBtn").show();
    $(e).parents(".formContent").find(".block").hide();
    $(e).parents(".formContent").find(".verificationInput").show();
    $(e).parents(".formContent").find(".block").each(function () {
		if($(this).find("input").val() !=""){
            $(this).show();
		}
    })

}

function getPanalImgList(objID,imgStr){
	var content = "";
    if(imgStr){
        var imgsArr = imgStr.split(",");

        if(imgsArr.length>0){

            for(var i=0;i<imgsArr.length;i++){
                //该判断用于排除尾逗号的空值
                if(imgsArr[i]!=""){
                    content +='<a class="form_picture_list" href="'+basePath+'/filesManager/showFile?url='+imgsArr[i]+'"><img src="'+basePath+'/filesManager/showFile?url='+imgsArr[i]+'"/></a>';
                }
            }
        }
    }
    content +="<div class='clear'></div>";
	$("#"+objID).html(content);
    $(".form_picture_list").colorbox({rel:'.form_picture_list',width:'60%',height:"600px"});
}

$(function () {
    // $(".tosearch_panel").click(function (e) {
		// $(this).parents(".searchBar_box").find(".searchBar_Blue").slideDown(100);
    //     $(".tosearch_panel").hide();
    //     $(".hideSearch_panel").show();
    //     stopPropagation(e);
    // })
    // $(document).bind('click',function(){
    //     $(".searchBar_Blue").slideUp(100);
    //     $(".tosearch_panel").show();
    //     $(".hideSearch_panel").hide();
    // });
    // $(".searchBar_Blue").click(function (e) {
    //     stopPropagation(e);
    // })
});



